
const prefix = '_cctv_store_'
const Global = typeof window !== 'undefined' ? window : global

export const set = (key, value) => {
	try {
		if (!key) {
			throw new Error('key is required')
		}
		value = value ? JSON.stringify(value) : ''
		Global.localStorage.setItem(prefix + key, value)
	} catch (error) {
		console.log(error)
	}
}

export const get = (key) => {
	try {
		if (!key) {
			return null
		}
		const res = Global.localStorage.getItem(prefix + key)
		return res ? JSON.parse(res) : null
	} catch (error) {
		console.log(error)
	}
}

export const remove = (key) => {
	try {
		if (!key) {
			throw new Error('')
		}
		Global.localStorage.removeItem(key)
	} catch (error) {
		console.log(error)
	}
}

export const clearAll = () => {
	try {
		Global.localStorage.clear()
	} catch (error) {
		console.log(error)
	}
}
